var attGrid,attdata,select_MachineNumS,machinedata;
var jsonObj = {};
$(function() {
    $("#form_core").height($(".form_tab").height()-$("#form_option").outerHeight());
    $('#myTabs a').click(function (e) {
        e.preventDefault()
        $(this).tab('show')
    });
    attGrid = $("#attend_list").ligerGrid({
        columns:[
            {display:'机器序列号',name:'machsn',width:80,minWidth:60,align:'left',},
            {display:'机器号',name:'machcode',width:80,minWidth:60,align:'left'},
            {display:'设备名称',name:'machname',width:80,minWidth:60,align:'left'},
            {display:'设备IP',name:'machip',width:80,minWidth:60,align:'left'},
            {display:'用户编号',name:'userid',width:100,minWidth:60,align:'left'},
            {display:'验证方式',name:'verify_method',width:120,minWidth:60,align:'left'},
            {display:'考勤时间',name:'attendtime',width:150,minWidth:160,align:'left'},
            {display:'考勤状态',name:'attend_status',width:10,hide:true},
        ],
        usePager: false,
        dataAction:'server',
        contentType: "application/json; charset=utf-8",
        width:'96%',
        height:'96%',
        checkbox:false,
        rownumbers:true,
        fixedCellHeight:false,
        colDraggable:true,
        enabledEdit:false,
        clickToEdit:false,
        isScroll:true,
        onSelectRow:function(rowdata, rowindex){$("#txtrowindex").val(rowindex);},
    });
    //select控件绑定远程数据
    select_MachineNumS = bindSelect('MachineNum',get_machine("1"),[],false,true);
    $("#pageloading").hide();
});


//更新考勤数据
function updateData(){
	var url ="/attendance/updateData";
	ajaxSubmit(url, null, function(data) {
		if (parseInt(data['status']) > 0) {
			$.ligerDialog.success('更新数据成功！');
		} else {
			$.ligerDialog.error('保存失败');
		}
	});
}

//下载考勤数据到临时表中
function loadData(){
	var machinfo = $("#MachineNum").val().split("#");
	var machcode =  parseInt(machinfo[0]);
	var machip = machinfo[1];
	var machsn = machinfo[2];
	var machname = $("#MachineNum").text();
	var userid = $("#userid").val();
	var attendata;
	if(userid==null||userid==""){
		attendata = faceApplet.getGeneralLogData(machip,machcode);
	}else{
		attendata = faceApplet.getUserLogData(machip,machcode,userid);
	}
	var attenjson = JSON.parse(attendata);
	var jsonarray = new Array() ;
    for(var att in attenjson){  
        var arr  =
        {
            "machcode" :machcode,
            "machsn" : machsn,
            "machname":machname,
            "machip":machip,
            "userid" : attenjson[att].userid,
            "attendtime" : attenjson[att].time,
            "verify_method" : attenjson[att].VerifyMode,
            "attend_status" : attenjson[att].InOutMode
        }
        jsonarray.push(arr);
      }  
	jsonObj.Rows = jsonarray;
	attGrid.set({data: jsonObj}); 
	var jsonData = JSON.stringify(jsonObj);
	var url ="/attendance/loadAttendance";
	//保存提交后台
	ajaxSubmit(url, jsonData, function(data) {
		if (parseInt(data['status']) > 0) {
			$.ligerDialog.success('下载数据成功！');
		} else {
			$.ligerDialog.error('下载失败');
		}
	});
	
}
